/**
 * Created by dashan on 2017/3/26.
 */
var mongoose = require('mongoose');
mongoose.Promise = Promise;
mongoose.connect('mongodb://dev1.bjvca.com:27017/test2');

var OrderSchema = new mongoose.Schema({
    count:{
        type:Number,
        required:true,  // 验证，必填
        max:10000,    // 验证，最大值
        min:10    //验证，最小值
    },
    status:{
        type:String,
        enum:['created','success','failed']   //枚举验证器
    },
    desc:{
        type:String,
        match: /book/g,    //正则匹配
        validate: function(desc){   //自定义验证器
            return desc.length < 10;     //如果大于等于10就返回true,否则就返回false;
        }
    }
});


var Order = mongoose.model('Order',OrderSchema);

var order = new Order();
order.count = 10000;
order.status = 'success';
order.desc = '12349book';

order.save(function(err){

    if(err){
        console.log(err);
        return console.log("save failed:");
    }

    console.log("save success");
});